<?php
/*
 * 接口：/receive_record/add
 * 说明：新增领用记录
 */

//关闭事物自动提交
$db->mysqlDB->falseAutoCommit();

//获取请求参数
$params = $route->bodyParams;

//新增领用记录
$P1 = array(
  "orr_uid" => $params['orr_uid'],
  "orr_number" => $params['orr_number'],
  "orr_oosid" => $params['orr_oosid'],
  "orr_note" => $params['orr_note'],
  "orr_is_type" => $params['orr_is_type'],
  "orr_issue_id" => $params['orr_issue_id'],
  "orr_create_time" => $params['orr_create_time']
);
$R1 = $db->mysqlDB->automaticAdd($P1)->insertTransaction("easyd_oa_receive_record");


//计算剩余库存
$inventory = $params['inventory'] - $params['orr_number'];

//更新物品库存
$P2 = array(
  "update_where" => "oos_id",
  "oos_id"       => $params['orr_oosid'],
  "oos_number"   => $inventory
);

$R2 = $db->mysqlDB->automaticUpdate($P2)->update("easyd_oa_office_supplies");

if(!$R1||!$R2){
  $db->mysqlDB->rollBackCommint();
  $db->mysqlDB->trueAutoCommit();
  $response->responseData(false);
}else{
  $db->mysqlDB->actionCommint();
  $db->mysqlDB->trueAutoCommit();
  $response->responseData(true);
}


?>